package com.tony.mindwarning.service.impl;

import com.tony.mindwarning.mpper.InbroundMapper;
import com.tony.mindwarning.mpper.ProductMapper;
import com.tony.mindwarning.pojo.Inbround;
import com.tony.mindwarning.pojo.Product;
import com.tony.mindwarning.service.InbroundService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 *
 * @Title: InbroundServiceImpl
 * @Auther: 皮蛋布丁
 * @Date: 2021/04/10/22:04
 * @Description:
 */
@Service
public class InbroundServiceImpl implements InbroundService {

    @Resource
    InbroundMapper inbroundMapper;
    @Resource
    ProductMapper productMapper;

    /**
    * @Description: inbround 带事务
    * @Param: [inbround]
    * @return: int
    * @Author: 皮蛋布丁
    */
    @Override
    @Transactional
    public int inbround(Inbround inbround,int userId) {
        Product p=new Product();
        p.setPid(inbround.getPid());
        p.setPcount(inbround.getIncount());
        //入库修改库存
        int count = productMapper.updateProductCount(p,userId);
        if(count>0){
            //System.out.println(100/0);
            //新增出库记录
            inbroundMapper.inbround(inbround,userId);
        }
        return 1;
    }

    @Override
    public int getTotlCount() {
        return inbroundMapper.getTotlCount();
    }

    @Override
    public List<Inbround> getInbroundByPaage(Map<String, Object> map) {
        return inbroundMapper.getInbroundByPaage(map);
    }

    @Override
    public int deleteInbroundRecord(int id,int userId) {
        return inbroundMapper.deleteInbroundRecord(id,userId);
    }
}
